1. Field of the Invention
Embodiments of the present invention generally relate to data processing. In particular, methods, systems and article of manufacture are provided for ensuring coherency of data in databases.
2. Description of the Related Art
In data processing systems, it is desirable to economize storage accesses to improve the overall system performance. To this end, many applications manage data by buffering data (e.g., rows of a table) into memory. In this way accesses to a data resource manager (e.g., a database) can be reduced by accessing the buffered data rather the underlying table itself, which is a more time consuming operation. However, this approach is limited to cases in which the application buffering the data is the only application changing the data. This is so because if other applications are allowed to change the underlying table itself, the table and the buffered data will not be synchronized. As such, the application accessing the buffered data will retrieve data which does not reflect changes made to the table by other applications.
In some cases, modifications to the underlying table do not occur so that the underlying data and the buffered data are always synchronized. Alternatively, data modifications are not considered relevant to an application or user. For example, the modification may happen so infrequently so as to be irrelevant (e.g., no longer needed) when the data ultimately does change. As another example, the modified data may not be particularly relevant (e.g., a date in a Web page). In any such cases, it is desirable to avoid unnecessarily accessing the underlying table. To this end, a user may use Enterprise JavaBeans to advantage.
In a computer network using the client/server model, Enterprise JavaBeans (EJB) is an architecture for setting up program components that run on the server side of the computer network. EJB is built on the JavaBeans technology for distributing program components (which are called Beans) to clients in a network. In Enterprise JavaBeans, there are two types of beans: session beans and entity beans. An entity bean is described as one that, unlike a session bean, has persistence and can retain its original behavior or state.
EJB program components are written in the Java programming language. To deploy an EJB or component, it must be part of a specific application, called a xe2x80x9ccontainerxe2x80x9d. The application or container that runs the EJB is sometimes called an application server. A common use of EJBs is to provide an interface between users and an application and its database.
To improve processing efficiency and reduce accesses to a database, EJBs can be given a property called xe2x80x9cExclusivexe2x80x9d. When enabled, the exclusive property causes an EJB server to cache a bean so that, after a row has been stored to the bean (referred to as the xe2x80x9chydrationxe2x80x9d of the bean), access back to a database need not be made. However, this approach does not ensure that the data in the database will not be changed during the time the cached bean is being used. Accordingly, coherency of the data may still be compromised.
Therefore, there is a need for a method and system adapted to ensure the validity of data contained in cache or other working storage.
Embodiments of the present invention generally provide methods and systems for maintaining coherency of data. In particular, coherency is maintained between data contained in executable code and a source location of the data (e.g., a table of a database).
One embodiment provides a method comprising retrieving data from a data structure having a trigger defined thereon and placing the data with executable code configured to utilize the data and configured with a property indicating that the data will be accessed during execution instead of the data structure. The data structure is then modified. In response to modifying the data structure, the trigger is fired. In response to firing the trigger, the executable code is invalidated. In one embodiment, the data and the executable code are contained in working storage which may be, for example, volatile memory or storage.
Another embodiment provides a method, comprising hydrating an enterprise Java Bean (EJB) with data retrieved from a database data structure having a trigger defined thereon. The trigger is fired in response to modifying the database data structure. In response to firing the trigger, it is determined whether an invalidation criterion for the EJB has been satisfied. If so, the method comprises invalidating the EJB.
Yet another embodiment provides a computer-readable medium containing a program which, when executed by a processor, performs steps comprising processing a signal indicating that a trigger defined on a database data structure has fired in response to modifying the database data structure and determining whether an invalidation criterion for an enterprise Java Bean (EJB) associated with data retrieved from the database data structure has been satisfied. The invalidation criterion is satisfied according to a manner in which the data structure is modified. If the invalidation criterion is satisfied, the EJB is invalidated.
Still another embodiment provides a system, comprising a database containing at least one table having a trigger defined thereon, a memory area configured to temporarily store at least one EJB and an enterprise Java Bean (EJB) server configured to communicate with the database. The EJB is hydrated with data from the at least one table and configured with an exclusive property and an invalidation property that causes the EJB to be invalidated in response to the trigger firing when invalidation criterion is satisfied.
Still another embodiment provides a data structure contained in a memory, comprising a table identifier for a table contained in a database and having a trigger defined thereon, wherein the trigger is configured to fire upon modifying the table; a code identifier for an enterprise Java Bean (EJB) contained in a cache memory and hydrated with data from the table; and an invalidation criterion which, when satisfied as result of modifying the table, causes the EJB to be invalidated.